package threadDemo;

/**
* @author jie
* @version 创建时间：2018年10月13日 下午4:15:48
* 1个锁多个方法线程
*/
public class MutilThreadOneLock {
	static long start;
	public static void main(String[] args) {
		DrawView drawView = new DrawView();
		
		start = System.currentTimeMillis();
        Runnable runnable = new Runnable() {
	
        
			@Override
			public void run() {
				System.out.println("thread id =="+Thread.currentThread().getId());
				for (int i = 0; i < 100; i++) {
					try {
						drawView.add();
						Thread.sleep(10);
					} catch (InterruptedException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
				}
				System.out.println("结束时间addd: "+(System.currentTimeMillis()-start));
			}
		};
        Runnable runnable2 = new Runnable() {
			
			@Override
			public void run() {
				System.err.println("thread id =="+Thread.currentThread().getId());
				for (int i = 0; i < 100; i++) {
					try {
						drawView.del();
						Thread.sleep(10);
					} catch (InterruptedException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
				}
				System.err.println("结束时间delll: "+(System.currentTimeMillis()-start));
			}
		};

		new Thread(runnable).start();
		new Thread(runnable2).start();
	}

	

}

class DrawView{
	
	public void add (){
		synchronized (this) {
			System.out.println(System.currentTimeMillis()+"   addddddd");
		}
		
	}
	
	public void del (){
		synchronized (this) {
			System.err.println(System.currentTimeMillis()+"   dellllll");
		}
		
	}
	
	
}